package io.renren.modules.frt.service.impl;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.toolkit.StringUtils;

import io.renren.common.utils.MapUtils;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.frt.dao.SumaryDao;
import io.renren.modules.frt.entity.SumaryEntity;
import io.renren.modules.frt.service.SumaryService;


@Service("sumaryService")
public class SumaryServiceImpl extends ServiceImpl<SumaryDao, SumaryEntity> implements SumaryService {

    @SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
    public PageUtils queryPage(Map<String, Object> params) {
    	
    	EntityWrapper ew = new EntityWrapper<SumaryEntity>();
    			
    	ew.eq("user_id", (Long)params.get("userId"))
    	.eq("sumary_flag", 1)
    	.like(StringUtils.isNotEmpty(MapUtils.toStr(params, "taskName")), "task_name", MapUtils.toStr(params, "taskName"));
    	
    	Set<String> provinceSet = (Set<String>)params.get("provinceSet");
    	Iterator<String> itor = provinceSet.iterator();
    	
    	StringBuffer or = new StringBuffer();
    	while(itor.hasNext()) {
    		or.append(" data_source_ids like '%"+itor.next()+"%' ").append("or");
    	}
    	if(or.length() > 0) {
    		or.setLength(or.length() - 2);
    		ew.andNew(or.toString());
    	}
    	
        Page<SumaryEntity> page = this.selectPage(
                new Query<SumaryEntity>(params).getPage(),
                ew);

        return new PageUtils(page);
    }

}
